Imports System.Data.SqlClient
Imports System.Configuration

Public Class cImportInvestors

#Region "Declare"

    Public Event entInvRecordAdded()
    Private _DbFieldID As Integer
    Private _TemplateID As Integer
    Private _ESourceID As Integer
    Private _SourceTypeCode As String

#End Region

#Region "Properties"

    Public Property ESourceID() As Integer
        Get
            Return _ESourceID
        End Get
        Set(ByVal value As Integer)
            _ESourceID = value
        End Set
    End Property

    Public Property SourceTypeCode() As String
        Get
            Return _SourceTypeCode
        End Get
        Set(ByVal value As String)
            _SourceTypeCode = value
        End Set
    End Property

    Public Property TemplateID() As Integer
        Get
            Return _TemplateID
        End Get
        Set(ByVal value As Integer)
            _TemplateID = value
        End Set
    End Property

    Public Property DbFieldID() As Integer
        Get
            Return _DbFieldID
        End Get
        Set(ByVal value As Integer)
            _DbFieldID = value
        End Set
    End Property
#End Region

#Region "Methods"

    ''' <summary>
    ''' Created to Get the DisplayName and DbFieldId For Mapping Details
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SelectDatabaseFields(ByVal SourceTypeCode As String) As IDataReader
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlClient.SqlParameter
        param(0) = New SqlParameter("@SourceTypeCode", SourceTypeCode)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_GetDatabaseFieldsBySourceCode", CommandType.StoredProcedure, ReturnTypes.DataReader, param)
        Return CType(eReturnVal.ResultObject, IDataReader)
    End Function



    ''' <summary>
    '''  To Get Mapped FieldIds DBFieldID and Fieldname For Mapping Details
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetMappedColumns() As IDataReader
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlClient.SqlParameter
        param(0) = New SqlParameter("@TemplateID", TemplateID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_GetImportTemplateDetails", CommandType.StoredProcedure, ReturnTypes.DataReader, param)
        Return CType(eReturnVal.ResultObject, IDataReader)
    End Function

    ''' <summary>
    ''' To Check if any mandatory field left or not in Mapping Details
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function ChkImportInvestorIsIsmandatory() As ExecutionResult
        Dim eReturnVal As ExecutionResult = Nothing
        Const ARRAY_SIZE As Integer = 2
        'Try
        Dim param(ARRAY_SIZE) As SqlClient.SqlParameter
        param(0) = New SqlParameter("@ETemplateID", TemplateID)
        param(1) = New SqlParameter("@SourceTypeCode", SourceTypeCode)
        param(2) = New SqlParameter("@Name", SqlDbType.VarChar, 100)
        param(2).Direction = ParameterDirection.Output
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CheckTemplateMandatoryFields", CommandType.StoredProcedure, ReturnTypes.NonQuery, param)
        Return eReturnVal
        'Catch ex As Exception
        '    Throw ex
        'End Try
    End Function

    Public Shared Function SelectDatabaseField(ByVal sourceID As Integer) As IDataReader
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlClient.SqlParameter
        param(0) = New SqlParameter("@sourceID", sourceID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_GetDatabaseFieldsBySourceCode", CommandType.StoredProcedure, ReturnTypes.DataReader, param)
        Return CType(eReturnVal.ResultObject, IDataReader)
    End Function

#End Region
End Class


